﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace WS.EKA.UI.Business
{
    internal abstract class ReportBase<T> : IReport
    {
        //json default setting
        //protected ReportBase()
        //{
        //    JsonConvert.DefaultSettings = () =>
        //    {
        //        return new JsonSerializerSettings()
        //        {
        //            DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
        //        };
        //    };
        //}

        /// <summary>
        /// default is string collection
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public virtual string GetJsonString(object parameter)
        {
            var obj = parameter as ReportParameter<List<string>>;
            return JsonConvert.SerializeObject(obj.Data);
        }

        /// <summary>
        /// default implements
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public virtual void SendMessage(object parameter)
        {
            string message = GetJsonString(parameter);
            WebSocketClient.SendMessage(Key, message);
        }

        public virtual string GetJsonData<T>(ReportParameter<T> parameter)
        {
            return GetJsonString(parameter);
        }

        public virtual void Send<T>(ReportParameter<T> parameter)
        {
            SendMessage(parameter);
        }

        public virtual WebSocketClientType Key
        {
            get { return WebSocketClientType.None; }
        }
    }
}
